package logic

import (
	"context"
	"renting-demo/houseorder_srv/houseorder"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateHouseOrderLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateHouseOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateHouseOrderLogic {
	return &CreateHouseOrderLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateHouseOrderLogic) CreateHouseOrder(req *types.CreateOrderRequest) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.HouseOrderServer.CreateOrder(context.Background(), &houseorder.CreateOrderRequest{
		UserID:     int64(req.UserId),
		HouseId:    int64(req.HouseId),
		Date:       int64(req.Date),
		HousePrice: int64(req.HousePrice),
		Amount:     int64(req.Amount),
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "房源订单创建失败",
		}, nil
	}
	return &types.Data{
		Code:    200,
		Message: "房源订单创建成功",
	}, nil
}
